﻿@page "/Manager/Index"
@layout ManagerLayout
@using EmployeeLeaveSystem.Shared.Models
@inject HttpClient _HttpClient
@implements IPageFlush
<Title>人员请假审核</Title>
<Title Level="2">需要我审核的</Title>
<Table DataSource="@GobalManager.myInfo?.AcceptHistory"
       TItem="LeaveDetail"
       @bind-SelectedRows="selectedRows">
    <Selection Key="@(context.Id.ToString())" />
    <PropertyColumn Property="x=>x.Id" Sortable />
    <PropertyColumn Property="x=>x.Name" />
    <PropertyColumn Property="x=>x.StartTime" />
    <PropertyColumn Property="x=>x.EndTime" />
    <PropertyColumn Property="x=>x.LeaveDate" Title="发起日期" />
    <PropertyColumn Property="x=>x.AcceptFlag" Title="当前状态" />
    <ActionColumn Title="操作">
        <Button OnClick="()=>{
            LeaveDetailsInfo.Id = context.Id;
            modalVis=true;}">
            查看
        </Button>
        @if (context?.AcceptFlag == AcceptFlag.审核中) {
            <Button OnClick="()=>{App._appHandle.AcceptMsgToIdLeaveDetail(context.Id);}" Type="@ButtonType.Link">批准</Button>
            <Button Danger OnClick="()=>{App._appHandle.RejectMsgToIdLeaveDetail(context.Id);}" Type="@ButtonType.Link">驳回</Button>
        }
    </ActionColumn>
</Table>
<Title Level="2">批量操作</Title>
<h5>当前选择：</h5>
@if (selectedRows != null && selectedRows.Any()) {
    <Button Danger Size="small" OnClick="@(e => { selectedRows = null; })">Clear</Button>
    @foreach (var selected in selectedRows) {
        <Tag @key="selected.Id">@selected.Id - @selected.Name</Tag>
    }
    <h5>说明原因：</h5>
    <TextArea @bind-Value=text Placeholder="输入接收/驳回的全部原因"></TextArea>
    <Button>批准</Button>
    <Button>驳回</Button>
}

<Modal Footer="null"
       Draggable=false
       Visible=modalVis
       Width="@("80vw")"
       OnCancel="()=>{modalVis=false;}"
       Maximizable=true>
    <LeaveDetailsInfo />
</Modal>

@code {
    bool modalVis = false;
    string text { get; set; } = "";
    IEnumerable<LeaveDetail> selectedRows;

    protected override void OnInitialized() {
        GobalManager.AddPage(this);
        base.OnInitialized();
    }

    protected override async Task OnInitializedAsync() {
        var netRes = await _HttpClient.GetFromJsonAsync<List<LeaveDetail>>($"Main/GetAcceptLeaveDetaiByUsrId?id={GobalManager.myInfo?.Id}");
        if (netRes != null && GobalManager.myInfo != null) {
            GobalManager.myInfo.AcceptHistory = netRes;
        }
        StateHasChanged();
        await base.OnInitializedAsync();
    }
    public void Flush() {
        StateHasChanged();
    }

}
